home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / chkflp.exe / CFLOP.ASM < prev    next >
Assembly Source File  |  1991-12-05  |  8KB  |  201 lines

  1. ; File......: FLOPTST.ASM
  2. ; Author....: Joseph LaCour
  3. ; Date......: $Date:   15 Aug 1991 23:07:48  $
  4. ; Revision..: $Revision:   1.2  $
  5. ; Log file..: $Logfile:   E:/nanfor/src/floptst.asv  $
  6. ; This is an original work by Joseph LaCour and is placed in the
  7. ; public domain.
  8. ;
  9. ;
  10. ;  ACKNOWLEDGEMENTS:
  11. ;
  12. ;          PAOLO RAMOZZI FOR HIS WORK IN DBDCHECK FOR SHOWING HOW TO
  13. ;          USE INT 13H.
  14. ;
  15. ;
  16. ; Modification history:
  17. ; ---------------------
  18. ;
  19. ; $Log:   E:/nanfor/src/floptst.asv  $
  20. ;  
  21. :     Rev 2.0   04 Dec 1991 09:16:00   Kevin Traub
  22. ;  Modified to be a 'c' callable function. Calling convention:
  23. ;        extern unsigned far ft_floptst(int drivenumber);
  24.  
  25. ;  Removed Clipper interface, and removed check for invalid parameters to
  26. ;  reduce overhead. Clipper Program was about 115k, 'c' .exe is now about 4k.
  27. ;  use MS Masm 5.1 or higher to assemble - No arguments, Model already defined
  28. ;  as Large.
  29. ;  Compile accompanying 'c' pgm as large model and link with defaults
  30. ;  eg: masm cflop.asm;
  31. ;      cl /AL /c callclp.c
  32. ;      link callcflp.obj+cflop.obj;
  33. ;
  34. ;  Executable callcflp will set DOS ERRORLEVEL based on condition of specified
  35. ;  floppy. eg. callcflp A    - will test drive A for readiness, if drive is
  36. ;  not ready (Door open or no disk) .exe will set ERRORLEVEL to 1, and will
  37. ;  temporarily (duration of callcflp.exe) intercept DOS critical error handler
  38. ;  so there will be no RETRY,IGNORE,ABORT, FAIL? message.
  39. ;  ERRORLEVELS set as follows:
  40. ;    0 - Drive Loaded and ready to read or write
  41. ;    1 - Drive Door Open or Diskette inserted upside down
  42. ;    2 - Diskette is unformatted
  43. ;    3 - Write protected
  44. ;    4 - Undetermined
  45. ;  Arguments to callcflp.exe are A or B, case insensitive, : not necessary.
  46. ;
  47. ;     Rev 1.2   15 Aug 1991 23:07:48   GLENN
  48. ;  Forest Belt proofread/edited/cleaned up doc
  49. ;  
  50. ;     Rev 1.1   11 May 1991 00:21:42   GLENN
  51. ;  File header changed to conform to Toolkit standard.
  52. ;
  53. ;  $DESCRIPTION$
  54. ;      FT_FLOPTST() returns a numeric code designating the
  55. ;      diskette drive's status.
  56. ;
  57. ;      FT_FLOPTST() is particularly useful in backup and restore programs
  58. ;      that need to test the floppy drive before writing/reading from a
  59. ;      floppy disk.
  60.  
  61.  
  62. .MODEL LARGE
  63.  
  64. _FT_DATASEG  SEGMENT PUBLIC  'DATA'
  65.  
  66. FDRIVE          DB      0
  67. BOOT_SECT       DB      512 DUP (0)
  68.  
  69. _FT_DATASEG  ENDS
  70.  
  71. _NANFOR   SEGMENT 'CODE'
  72.         ASSUME  CS:_NANFOR,DS:_FT_DATASEG,ES:_FT_DATASEG,SS:NOTHING
  73.  
  74. public   _ft_floptst
  75. _ft_floptst      proc    far
  76.  
  77.                 push    bp              ; Entry sequence - save old BP
  78.                 mov     bp,sp           ; Set stack framepointer
  79.  
  80.                 mov     ax,[bp+6]       ; Load Arg2 into AX
  81.  
  82.  
  83.                 push    ax              ; save drive
  84.                 PUSH    AX
  85.                 int     11h             ; get equipment list
  86.                 mov     ah,0            ; clear high byte
  87.                 mov     cl,6            ; set shift count
  88.                 shr     al,cl           ; shift diskette count
  89.                 pop     bx              ; restore drive
  90.                 cmp     bl,al           ; does drive exist?
  91.                 jbe     ParamOk         ; yes, so continue
  92. derror:         jmp     short Ferror    ; Invalid drive
  93.  
  94. ParamOk:
  95.                 POP     AX
  96.                 push    ds              ; Save DS
  97.                 mov     dx,_FT_DATASEG  ; DATA SEGMENT
  98.                 MOV     DS,DX           ; IN DS REGISTER
  99.                 MOV     ES,DX           ; IN ES REGISTER
  100.                 MOV     FDRIVE,AL       ; SAVE DRIVE NUMBER
  101.                 XOR     AX,AX           ; RESET DISKETTE SYSTEM
  102.                 INT     13H             ; CALL BIOS
  103.                 CALL    _FTFLOPT        ; TEST DISKETTE TYPE
  104.                 POP     DS              ; RESTORE DS
  105.                 JMP     SHORT EXIT      ; RETURN
  106.  
  107. FERROR:
  108.                 MOV     AX,-1           ; BAD PARAMETERS
  109.  
  110. EXIT:
  111.                                         ; Leave return value in AX
  112.  
  113.                 pop     bp              ; Restore old framepointer
  114.                 ret     4               ; Exit, and restore 4 bytes of args
  115.  
  116. _ft_floptst      endp
  117.  
  118. ;-----------------------------------------------------------;
  119. ; LOCAL SUBROUTINE - CALL BIOS INT 13 FOR READ SECTOR       ;
  120. ;-----------------------------------------------------------;
  121.  
  122. _FTINT13        PROC    NEAR
  123.                 PUSH    BX              ; SAVE REGS
  124.                 PUSH    ES              ;
  125.                 PUSH    AX              ;
  126.                 INT     13H             ; CALL BIOS (read sector)
  127.                 jnc     ftIntRet        ; Read ok. Exit
  128.                 xor     ax,ax           ; reset diskette system
  129.                 int     13h             ; call BIOS
  130.                 pop     ax              ; restore regs
  131.                 pop     es              ; for retry
  132.                 push    es              ; save regs
  133.                 push    ax              ;
  134.                 int     13h             ; call BIOS (read sector)
  135.                 jnc     ftIntRet        ; Read ok. Exit
  136.                 xor     ax,ax           ; reset diskette system
  137.                 int     13h             ; call BIOS
  138.                 pop     ax              ; restore regs
  139.                 pop     es              ; for retry
  140.                 push    es              ; save regs
  141.                 push    ax              ;
  142.                 int     13h             ; call BIOS (read sector)
  143. ftIntRet:       pop     bx              ; restore regs
  144.                 pop     es              ;
  145.                 pop     bx              ;
  146.                 ret                     ; near return
  147.  
  148. _ftint13        endp
  149.  
  150. ;-----------------------------------------------------------;
  151. ; Local subroutine - check boot sector                      ;
  152. ;-----------------------------------------------------------;
  153.  
  154. _ftflopt        proc    near
  155.  
  156.                 push    di              ; preserve
  157.                 mov     di,OFFSET _FT_DataSeg:boot_sect   ; address of buffer
  158. ftflopred:
  159.                 xor     dx,dx           ; clear DX
  160.                 mov     dl,fdrive       ; drive number in DL
  161.                 mov     cx,0001h        ; track 0, sector 1
  162.                 mov     bx,di           ; buffer addr in ES:BX
  163.                 mov     ax,0201h        ; read one sector
  164.                 call    _ftint13        ; call BIOS
  165.                 jnc     Flop1           ; Read ok. Continue
  166.                 cmp     ah,80h          ; drive not ready ?
  167.                 je      Flop_out        ; Yes.
  168.                 cmp     ah,02h          ; unformatted?
  169.                 je      Flop_for        ; Yes
  170.                 mov     ax,4            ; otherwise, unknown
  171.                 jmp     short Flop_End  ; and exit
  172. Flop1:
  173.                 xor     dx,dx           ; clear DX
  174.                 mov     dl,fdrive       ; drive number in DL
  175.                 mov     cx,0001h        ; track 0, sector 1
  176.                 mov     bx,di           ; buffer addr in ES:BX
  177.                 mov     ax,0301h        ; write one sector
  178.                 call    _ftint13        ; call BIOS
  179.                 jnc     Flop_OK         ; Write ok. Disk s/b AOK
  180.                 cmp     ah,03h          ; Write protected?
  181.                 jne     Flop_OK         ; No disk AOK
  182.                 mov     ax,3
  183.                 jmp     short Flop_End
  184. Flop_out:
  185.                 mov     ax,1
  186.                 jmp     short Flop_End
  187. Flop_for:
  188.                 mov     ax,2
  189.                 jmp     short Flop_End
  190. Flop_OK:
  191.                 xor     ax,ax           ; AX = 0
  192. Flop_End:
  193.                 pop     di              ; restore
  194.                 ret                     ; near return
  195.  
  196. _ftflopt        endp
  197.  
  198. _nanfor         ends
  199.                 end
  200.